import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/pages/main/main_page.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/utils/js_tool.dart';
import 'package:yysk_app/widget/circle_arrow_back_widget.dart';

class AppBarBackWidget extends StatelessWidget {
  final BuildContext context;
  final VoidCallback? onBack;
  final VoidCallback? beforBack;
  final bool needReturn; //加个开关不走默认路由
  final double marginLeft;
  final Color? backgroundColor;
  const AppBarBackWidget({
    super.key,
    required this.context,
    this.onBack,
    this.beforBack,
    this.needReturn = false,
    this.marginLeft = 16,
    this.backgroundColor = AppColors.backgroundColor,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if (beforBack != null) {
          beforBack!();
        } else {
          if (onBack != null) {
            onBack!();
          }
          if (needReturn == true) {
            return;
          }
          if (Navigator.canPop(context)) {
            Get.back();
          } else {
            Get.offAllNamed(MainPage.path);
          }
        }
      },
      child: Container(
        decoration: BoxDecoration(),
        // color: AppColors.backgroundColorLightGreen,
        child: Center(
          child: CircleArrowBackWidget(
            marginLeft: marginLeft.px,
            backgroundColor: backgroundColor,
            onPressed: null,
          ),
        ),
      ),
    );
  }
}
